plotly_flyfox <- ggplot() + geom_point(data=data_flyfox,
aes(utm.easting, utm.northing,
color=individual.local.identifier)) +
labs(x="Easting", y="Northing") +
guides(color=guide_legend("Identifier"))
plotly::ggplotly(plotly_flyfox)
data_flyfox %>% group_by(individual.local.identifier) %>%
summarise(n())
## # A tibble: 27 × 2
## individual.local.identifier `n()`
## <int> <int>
## 1 261 284
## 2 325 54
## 3 423 260
## 4 434 197
## 5 486 131
## 6 556 528
## 7 570 310
## 8 577 321
## 9 602 219
## 10 606 285
## # ℹ 17 more rows
list_flyfox_ind_full <- split(data_flyfox, data_flyfox$individual.local.identifier)
list_flyfox_ind <- list_flyfox_ind_full[1:10]
flyfox_ind <- names(list_flyfox_ind)
ortho <- "images/christmas.tif"
image_stack <- raster::stack(ortho)
crop_full <- raster::extent(min(data_flyfox$utm.easting-5000),
max(data_flyfox$utm.easting+5000),
min(data_flyfox$utm.northing-5000),
max(data_flyfox$utm.northing+5000))
x_coord <- c(min(data_flyfox$utm.easting-5000), max(data_flyfox$utm.easting+5000))
y_coord <- c(min(data_flyfox$utm.northing-5000), max(data_flyfox$utm.northing+5000))
image_full <- crop(image_stack, crop_full)
map_christmas <- as.data.frame(image_full, xy = TRUE) %>% setNames(c("x", "y", "red", "green", "blue"))
ggplot()+geom_spatial_rgb(data = map_christmas, aes(x=x, y=y, r=red, g=green, b=blue))+coord_sf() + scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0))
function_kde <- function(individual_kde){
data <- individual_kde
x <- as.data.frame(data$utm.easting)
y <- as.data.frame(data$utm.northing)
xy <- c(x,y)
data.proj <- SpatialPointsDataFrame(xy, data, proj4string = CRS("+proj=utm +zone=48 +datum=WGS84 +units=m +no_defs"))
xy.sp <- SpatialPoints(data.proj@coords)
kde<-kernelUD(xy.sp, h="href", kern="bivnorm", extent = 3, grid=200)
ver95 <- getverticeshr(kde, 95)
ver85 <- getverticeshr(kde, 85)
ver75 <- getverticeshr(kde, 75)
kde.points <- cbind((data.frame(xy)),data$individual.local.identifier)
colnames(kde.points) <- c("x","y","identifier")
kde95.sf <- st_as_sf(ver95)
kde85.sf <- st_as_sf(ver85)
kde75.sf <- st_as_sf(ver75)
kde.plot <- ggplot() + theme_bw() +
theme(axis.text.y = element_text(angle = 90, hjust = 0.5, vjust = 0.5)) +
geom_spatial_rgb(data = map_christmas, aes(x=x, y=y, r=red, g=green, b=blue)) +
geom_sf(data=kde95.sf, fill = "blue", alpha = 0.4) +
geom_sf(data=kde85.sf, fill = "green", alpha = 0.3) +
geom_sf(data=kde75.sf, fill = "yellow", alpha = 0.2) +
geom_point(data=kde.points, aes(x=x, y=y), color = "lightgray") +
coord_sf(xlim = x_coord, ylim = y_coord) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
labs(x="Easting (m)", y="Northing (m)", title=kde.points$identifier) +
theme(legend.position="none", plot.title = element_text(face = "bold", hjust = 0.5))
kde.plot + annotate("text", x = 560000, y = 8831000, label = paste("95% ",round(ver95$area,2)," ha"),
fontface = "bold", size = 3, color = "white")
}
pblapply(list_flyfox_ind, function_kde)
## $`261`
##
## $`325`
##
## $`423`
##
## $`434`
##
## $`486`
##
## $`556`
##
## $`570`
##
## $`577`
##
## $`602`
##
## $`606`